
**Replication Do File
**Enns, Peter K. 2015. ``Relative Policy Support and Coincidental Representation''
**Pespectives on Politics. 13(4): 1053-1064.

*Use: GilensReplicationData.dta
*which is a subset of Gilens' (2014) data available at:
*http://www.russellsage.org/research/data/economic-inequality-and-political-representation


*****************
**Recode outcome so dichotomous
*****************

gen policyadopted =.
recode policyadopted .=0 if OUTCOME==0
recode policyadopted .=1 if OUTCOME==2
recode policyadopted .=1 if OUTCOME==3
recode policyadopted .=1 if OUTCOME==4

******************
**Recode variables as log of odds ratio
**Gilens 2012, p.74
******************

gen  pred50_sw_lor = log(pred50_sw/(1- pred50_sw))
label var pred50_sw_lor "log of odds ratio: pred50_sw"

gen  pred90_sw_lor = log(pred90_sw/(1- pred90_sw))
label var pred90_sw_lor "log of odds ratio: pred90_sw"


**Verify Variables Coded correctly
**Perfect replication of Gilens 2012, Table 3.3 50th and 90th Income Percentiles, Row 3 (p.79)
logit policyadopted pred50_sw_lor  if  abs(pred90_sw - pred50_sw)>.1
logit policyadopted pred90_sw_lor  if  abs(pred90_sw - pred50_sw)>.1
pause


********************************************
***Figure 1
***Replication of Gilens 2012, Fig. 3.2, percent adopted by public support
********************************************
tab policyadopted if PREDALL_SW>=0 & PREDALL_SW<.1
tab policyadopted if PREDALL_SW>=.1 & PREDALL_SW<.2
tab policyadopted if PREDALL_SW>=.2 & PREDALL_SW<.3
tab policyadopted if PREDALL_SW>=.3 & PREDALL_SW<.4
tab policyadopted if PREDALL_SW>=.4 & PREDALL_SW<.5
tab policyadopted if PREDALL_SW>=.5 & PREDALL_SW<.6
tab policyadopted if PREDALL_SW>=.6 & PREDALL_SW<.7
tab policyadopted if PREDALL_SW>=.7 & PREDALL_SW<.8
tab policyadopted if PREDALL_SW>=.8 & PREDALL_SW<.9
tab policyadopted if PREDALL_SW>=.9 & PREDALL_SW<=1

********************************************
***Figures 2-4 are hypothetical scenarios
********************************************


********************************
***Figure 5
***Note: Actual figure in the article generated in Excel
********************************
twoway scatter pred90_sw pred50_sw 

********************************
**Figure 6
********************************

logit policyadopted pred90_sw_lor  if  abs(pred90_sw - pred50_sw)>.1
*gen 95% confidence interval around predicted probability
*http://www.stata.com/support/faqs/statistics/prediction-confidence-intervals/
predict lr_index if e(sample), xb 
predict se_index if e(sample), stdp
gen lb = lr_index - invnormal(0.975)*se_index if e(sample)
gen ub = lr_index + invnormal(0.975)*se_index if e(sample)
gen plb = exp(lb)/(1+exp(lb)) if e(sample)
gen pub = exp(ub)/(1+exp(ub)) if e(sample)

gen yhat_hi=exp(-.864055+(.4654377*pred90_sw_lor))/(1+exp(-.864055+(.4654377*pred90_sw_lor))) if e(sample)
gen yhat_mid=exp(-.864055+(.4654377*pred50_sw_lor))/(1+exp(-.864055+(.4654377*pred50_sw_lor))) if e(sample)

twoway scatter yhat_hi pred90_sw,msize(small) mcolor(gs10) || rcap  plb pub pred90_sw, msize(vtiny) lcolor(gs10) || scatter yhat_mid pred90_sw, msize(small) mcolor(black) || qfit yhat_mid pred90_sw, lcolor(black) ylabel(, nogrid) xtitle("Preferences 90th Income Percentile") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(.2 .8)) yscale(r(0 1)) ylabel(0(.2)1)  legend(region(lwidth(none)) col(1) ring(0) bplacement(nwest) lab(1 "Predicted Value (90th Income Percentile)") lab(2 "95% CI (90th Income Percentile)") lab(3 "Predicted Value (50th Income Percentile)") lab(4 "Quadratic Fit (50th Income Percentile)"))


********************************
**Figure 7
********************************

*Identify partisanship variables that include strong partisans 
*(i.e., not missing a value for Strong Republican and not 0 strong Republicans)
gen strongpid = 0
recode strongpid 0=1 if pid7_fav!=. & pid7_fav!=0

gen perfav_strongrep = .
replace perfav_strongrep = (pid1_fav)/(pid1_fav+pid1_opp+pid1_dk) if strongpid==1

gen perfav_strongdem = .
replace perfav_strongdem = (pid7_fav)/(pid7_fav+pid7_opp+pid7_dk) if strongpid==1

gen strongrep_lor = log(perfav_strongrep/(1- perfav_strongrep))
gen strongdem_lor = log(perfav_strongdem/(1- perfav_strongdem))


logit policyadopted strongrep_lor if abs(perfav_strongrep-perfav_strongdem)>.1
gen yhat_strep=exp(-1.014268+(.790888*strongrep_lor))/(1+exp(-1.014268+(.790888*strongrep_lor))) if e(sample)
gen yhat_stdem=exp(-1.014268+(.790888*strongdem_lor))/(1+exp(-1.014268+(.790888*strongdem_lor))) if e(sample)
predict lr_index_rep if e(sample), xb 
predict se_index_rep if e(sample), stdp
gen lb_rep = lr_index_rep - invnormal(0.975)*se_index_rep if e(sample)
gen ub_rep = lr_index_rep + invnormal(0.975)*se_index_rep if e(sample)
gen plb_rep = exp(lb_rep)/(1+exp(lb_rep)) if e(sample)
gen pub_rep = exp(ub_rep)/(1+exp(ub_rep)) if e(sample)

twoway scatter yhat_strep perfav_strongrep,msize(small) mcolor(gs10) || rcap  plb_rep pub_rep perfav_strongrep, msize(vtiny) lcolor(gs10) || scatter yhat_stdem perfav_strongrep, msize(small) mcolor(black) || qfit yhat_stdem perfav_strongrep, lcolor(black) ylabel(, nogrid) xtitle("Preferences of Strong Republicans") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(.2 .8)) legend(region(lwidth(none)) col(1) ring(0) bplacement(nwest) lab(1 "Predicted Value (Strong Rep)") lab(2 "95% CI (Strong Rep)") lab(3 "Predicted Value (Strong Dem)") lab(4 "Quadratic Fit (Strong Dem)"))




****************************************
****Online Appendix
****************************************

*************************************
**Figure A-1
*************************************

twoway scatter yhat_hi pred50_sw,msize(small) mcolor(gs10) || rcap  plb pub pred50_sw, msize(vtiny) lcolor(gs10) || scatter yhat_mid pred50_sw, msize(small) mcolor(black)  ylabel(, nogrid) xtitle("Preferences 50th Income Percentile") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(0 1)) yscale(r(0 1)) ylabel(0(.2)1)  legend(region(lwidth(none)) col(1) ring(0) bplacement(nwest) lab(1 "Predicted Value (90th Income Percentile)") lab(2 "95% CI (90th Income Percentile)") lab(3 "Predicted Value (50th Income Percentile)"))


*************************************
**Figure A-2
*************************************

logit policyadopted pred90_sw_lor if abs(pred90_sw - pred50_sw)>.1 & ECYN==1 | abs(pred90_sw - pred50_sw)>.1 &  SWYN==1
mat define b = get(_b)
predict pred_econ if e(sample), xb 
predict se_econ if e(sample), stdp
gen lb_econ = pred_econ - invnormal(0.975)*se_econ if e(sample)
gen ub_econ = pred_econ + invnormal(0.975)*se_econ if e(sample)
gen plb_econ = exp(lb_econ)/(1+exp(lb_econ)) if e(sample)
gen pub_econ = exp(ub_econ)/(1+exp(ub_econ)) if e(sample)

gen yhat_hiecon=exp(b[1,2]+(b[1,1]*pred90_sw_lor))/(1+exp(b[1,2]+(b[1,1]*pred90_sw_lor))) if e(sample)
gen yhat_midecon=exp(b[1,2]+(b[1,1]*pred50_sw_lor))/(1+exp(b[1,2]+(b[1,1]*pred50_sw_lor))) if e(sample)

twoway scatter yhat_hiecon pred90_sw,msize(small) mcolor(gs10) || rcap  plb_econ pub_econ pred90_sw, msize(vtiny) lcolor(gs10) || scatter yhat_midecon pred90_sw, msize(small) mcolor(black) || qfit yhat_midecon pred90_sw, lcolor(black) ylabel(, nogrid) xtitle("Preferences 90th Income Percentile") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(.2 .8)) yscale(r(0 1)) ylabel(0(.2)1)  legend(region(lwidth(none)) col(1) ring(0) bplacement(nwest) lab(1 "Predicted Value (90th Income Percentile)") lab(2 "95% CI (90th Income Percentile)") lab(3 "Predicted Value (50th Income Percentile)") lab(4 "Quadratic Fit (50th Income Percentile)"))
mat drop b

*************************************
**Figure A-3
*************************************
gen netigfav = log(INTGRP_STFAV + (.5*INTGRP_SWFAV) + 1) - log(INTGRP_STOPP + (.5*INTGRP_SWOPP) + 1)

egen pred90lor01 = std01(pred90_sw_lor)
egen pred50lor01 = std01(pred50_sw_lor)
egen netigfav01 = std01(netigfav)

*Coefficients from Gilens and Page 2014, Table 3, Col. 4 (p.571)
gen yhat_gp=exp((.03*pred50lor01 + .76*pred90lor01 + .56*netigfav01))/(1+exp((.03*pred50lor01 + .76*pred90lor01 + .56*netigfav01)))
gen yhat_gpmid=exp((.76*pred50lor01 + .03*pred90lor01 + .56*netigfav01))/(1+exp((.76*pred50lor01 + .03*pred90lor01 + .56*netigfav01)))

*90th Income Percentile
*region(lwidth(none)) lab(1 "Predicted Value (90th Income Percentile)")
twoway scatter yhat_gp pred90_sw, text(.77 .5 "Predicted Values (90th Income Percentile)", color(black)) msize(small) mcolor(gs10) ylabel(, nogrid) xtitle("Preferences 90th Income Percentile") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(.2 .8)) yscale(r(.5 .8)) ylabel(.5(.1).8) legend(off)  name(panela, replace) 
*50th Income Percentile
twoway scatter yhat_gpmid pred90_sw, text(.77 .5 "Predicted Values (50th Income Percentile)", color(black)) msize(small) mcolor(black) ylabel(, nogrid) xtitle("Preferences 90th Income Percentile") ytitle("Predicted Probability of Policy Adoption") graphregion(fcolor(white) lcolor(white)) plotregion(lcolor(black)) xlabel(.2[.2].8) xscale(r(.2 .8)) yscale(r(.5 .8)) ylabel(.5(.1).8)  legend(region(lwidth(none)) col(1) ring(0) bplacement(nwest) lab(1 "Predicted Value (50th Income Percentile)")) name(panelb, replace)
graph combine panela panelb, cols(2)

*************************************
**Table A-1
*************************************
logit policyadopted strongrep_lor if abs(perfav_strongrep-perfav_strongdem)>.1
logit policyadopted strongdem_lor if abs(perfav_strongrep-perfav_strongdem)>.1

keep OUTCOME pred50_sw pred90_sw PREDALL_SW pid1_fav pid1_opp pid1_dk pid7_fav pid7_opp pid7_dk ECYN SWYN INTGRP_STFAV INTGRP_SWFAV INTGRP_STOPP INTGRP_SWOPP 
